package ru.usu.gv.utils.generators;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import ru.usu.gv.core.I18nService;
import ru.usu.gv.graph.Graph;
import ru.usu.gv.gui.component.GVIntegerField;
import ru.usu.gv.gui.component.GVSlider;
import ru.usu.gv.utils.RandomUtilities;

/**
 @author Sergey Pupyrev 
 14.05.2007
 */

public class RandomGenerator extends GraphGeneratorBase
{
    private GVIntegerField field;
    private GVSlider slider;

    @Override
    public void customizePanel(JPanel panel)
    {
        super.customizePanel(panel);

        JPanel newPanel = new JPanel();
        panel.add(newPanel);
        newPanel.setLayout(new BoxLayout(newPanel, BoxLayout.Y_AXIS));

        field = new GVIntegerField(I18nService.get("generator.random.count"), 100, true);
        slider = new GVSlider(I18nService.get("generator.random.prob"), 0, 100, 10, true);

        newPanel.add(field);
        newPanel.add(slider);
    }

    public Graph generate(JPanel panel)
    {
        int count = field.getValue();
        double freq = slider.getValue() / 100.0;
        return RandomUtilities.generateRandomGraph(count, freq);
    }

    public String getTitle()
    {
        return I18nService.get("generator.random");
    }

}
